package top.huntwolf.admin.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.huntwolf.admin.common.enums.OrderStatus;
import top.huntwolf.admin.dao.*;
import top.huntwolf.admin.pojo.orderEntity.Order;

import java.util.List;

@Service
@Transactional
public class CMSOrderService {

    @Autowired
    private CMSOrderDao cmsOrderDao;

    public PageInfo<Order> selectAllOrder(int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Order> orders= cmsOrderDao.selectAllOrder();
        PageInfo<Order> pageInfo = new PageInfo<>(orders);
        return pageInfo;

    }

    public void updateOrders(String orderId,OrderStatus orderStatus){
        cmsOrderDao.updateStatus(orderId,orderStatus);
    }

    public void addRemark(Order order){
        cmsOrderDao.update(order);
    }

    public PageInfo<Order> getOrderByStatus(OrderStatus orderStatus,Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Order> orders = cmsOrderDao.selectByStatus(orderStatus);
        PageInfo<Order> pageInfo = new PageInfo<>(orders);
        return pageInfo;
    }

}
